package com.lanyou.cook.entity.domain;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;

import org.apache.commons.beanutils.PropertyUtils;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.lanyou.cook.common.DefaultDateJsonSerializer;
import com.lanyou.cook.datadictionary.DBDataType;
import com.lanyou.cook.service.DataDictionaryService;

@Entity
@EntityListeners({ AuditingEntityListener.class })
@Table(name = "T_COOK_BU_DBLINK_IF_REL_D")
public class DBlinkInterfaceColumnDefinition{
	//DBLink接口关系子表ID
	private String id;
	
	private int version;
	//字段名
	private String columnName;
	//数据类型
	private String dataType;
	//列名
	private String columnCode;
	//数据类型长度
	private String dataTypeLength;
	
	private String creator;

	private String modifier;

	private Date createTime;

	private Date modifyTime;
	//dblink关联接口类
	private DBlinkInterface dblinkInterface;
	
	
	@Id
	@GeneratedValue(generator = "uuidGenerator")
	@GenericGenerator(name = "uuidGenerator", strategy = "uuid")
	@Column(name = " DBLINK_IF_REL_D_ID", length = 36)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}
	
	@Version
	@JsonIgnore
	public int getVersion() {
		return version;
	}

	public void setVersion(int version) {
		this.version = version;
	}
	
	@Column(name="COLUMN_NAME",length=10)
	public String getColumnName() {
		return columnName;
	}
	
	@ManyToOne
	@JoinColumn(name = "DBLINK_IF_REL_ID")
	public DBlinkInterface getDblinkInterface() {
		return dblinkInterface;
	}

	public void setDblinkInterface(DBlinkInterface dblinkInterface) {
		this.dblinkInterface = dblinkInterface;
	}

	public void setColumnName(String columnName) {
		this.columnName = columnName;
	}
	
	@Column(name="DATA_TYPE",length=20)
	public String getDataType() {
		return dataType;
	}

	public void setDataType(String dataType) {
		this.dataType = dataType;
	}
	
	@Column(name="COLUMN_CODE",length=20)
	public String getColumnCode() {
		return columnCode;
	}

	public void setColumnCode(String columnCode) {
		this.columnCode = columnCode;
	}

	
	
	@CreatedBy
	@Column(length = 50)
	public String getCreator() {
		return creator;
	}

	public void setCreator(String creator) {
		this.creator = creator;
	}

	@LastModifiedBy
	@Column(length = 50)
	public String getModifier() {
		return modifier;
	}

	public void setModifier(String modifier) {
		this.modifier = modifier;
	}

	@Column(name = "CREATED_DATE")
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	@CreatedDate
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "LAST_UPDATED_DATE")
	@JsonSerialize(using = DefaultDateJsonSerializer.class)
	@LastModifiedDate
	public Date getModifyTime() {
		return modifyTime;
	}

	public void setModifyTime(Date modifyTime) {
		this.modifyTime = modifyTime;
	}
	
	@Column(name="DATA_TYPE_LEN")
	public String getDataTypeLength() {
		return dataTypeLength;
	}

	public void setDataTypeLength(String dataTypeLength) {
		this.dataTypeLength = dataTypeLength;
	}
	
	@Transient
	public String getDBlinkInterfaceName() {
		try {
			return (String) PropertyUtils.getProperty(dblinkInterface, "id");
		} catch (Exception e) {
			return null;
		}
	}
	@Transient
	public String getDataTypeDisplay() {
		return DataDictionaryService.getInstance().getValueName(DBDataType.TypeCode, dataType);
	}
	
	
	
}